<?php echo view('header.html');?>

<body class="layui-view-bodys">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-body">

                    <div class="layui-form ">

                        <div class="layui-row layui-col-space15">
                            <!--左侧 主要内容-->
                            <div class="layui-col-md9">

                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span class="text-red">*</span>应用名称:</label>
                                    <div class="layui-input-block">
                                        <input type="text" value="<?=isset($data['name']) ? $data['name'] : ''?>" name="data[name]" lay-verify="required" placeholder="请输入应用名称" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">简介:</label>
                                    <div class="layui-input-block">
                                        <textarea name="data[description]" class="layui-textarea"><?=isset($data['description']) ? $data['description'] : ''?></textarea>
                                    </div>
                                </div>

                                <div class="layui-form-item" lay-filter="status">
                                    <label class="layui-form-label">状态:</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="data[status]" value="1" title="启用" checked>
                                        <input type="radio" name="data[status]" value="0" title="禁用">
                                    </div>
                                </div>


                                <div class="layui-form-item vars_keyvalue">
                                    <fieldset class="layui-elem-field">
                                        <legend><a name="neutral">参数设置</a></legend>
                                        <div class="multies">
                                            <?php if(isset($data['keyvalue']) && $data['keyvalue']):?>
                                            <?php foreach($data['keyvalue'] as $k=>$v):?>
                                            <div class="layui-block">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">(<?=$k+1?>):</label>
                                                    <div class="layui-input-inline mokui-md1">
                                                        <input autocomplete="off" class="layui-input" name="data[keyvalue][<?=$k?>][name]" placeholder="中文名称" type="text" value="<?=isset($v['name']) ? $v['name'] : ''?>" />
                                                    </div>
                                                    <div class="layui-input-inline mokui-md1">
                                                        <input autocomplete="off" class="layui-input" name="data[keyvalue][<?=$k?>][key]" placeholder="参数" type="text" value="<?=isset($v['key']) ? $v['key'] : ''?>" />
                                                    </div>
                                                    <div class="layui-input-inline" style="width: 300px;">
                                                        <input autocomplete="off" class="layui-input" name="data[keyvalue][<?=$k?>][value]" placeholder="参数值" type="text" value="<?=isset($v['value']) ? $v['value'] : ''?>" />
                                                    </div>
                                                </div>
                                            </div>
                                            <?php endforeach;?>
                                            <?php else:?>
                                            <div class="layui-block">
                                                <div class="layui-form-item">
                                                    <label class="layui-form-label">(1):</label>
                                                    <div class="layui-input-inline mokui-md1">
                                                        <input autocomplete="off" class="layui-input" name="data[keyvalue][0][name]" placeholder="中文名称" type="text" value="" />
                                                    </div>
                                                    <div class="layui-input-inline mokui-md1">
                                                        <input autocomplete="off" class="layui-input" name="data[keyvalue][0][key]" placeholder="参数" type="text" value="" />
                                                    </div>
                                                    <div class="layui-input-inline" style="width: 300px;">
                                                        <input autocomplete="off" class="layui-input" name="data[keyvalue][0][value]" placeholder="参数值" type="text" value="" />
                                                    </div>
                                                </div>
                                            </div>
                                            <?php endif;?>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-input-block">
                                                <button type="button" class="layui-btn layui-btn-sm layui-btn-default" id="add_group">添加一组</button>
                                            </div>
                                        </div>
                                    </fieldset>
                                </div>


                            </div>

                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-input-block">
                                <button class="layui-btn layui-btn-blue" lay-submit="" lay-filter="ams_submit">提交保存</button>
                            </div>
                        </div>

                    </div>

                </div>
            </div>
        </div>
    </div>
    <?php echo view('footer.html');?>
    <script type="text/javascript">
        layui.use(['form', 'jquery', 'layer', 'laydate', 'layedit', 'upload'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;

            
            //添加一组
            $("#add_group").on('click', function () {
                var k, i = $(".multies .layui-block").length;
                k = i;
                i = i + 1;
                var str = '<div class="layui-block"><div class="layui-form-item"><div class="layui-inline"><label class="layui-form-label">(' + i + '):</label>';
                str += '<div class="layui-input-inline mokui-md1"><input autocomplete="off" class="layui-input" name="data[keyvalue][' + k + '][name]" placeholder="中文名称" type="text" value="" /></div>';
                str += '<div class="layui-input-inline mokui-md1"><input autocomplete="off" class="layui-input" name="data[keyvalue][' + k + '][key]]" placeholder="参数" type="text" value="" /></div>';
                str += '<div class="layui-input-inline" style="width: 300px;"><input autocomplete="off" class="layui-input" name="data[keyvalue][' + k + '][value]" placeholder="参数值" type="text" value="" /></div>';
                str += '</div></div></div>';
                $('.multies').append(str);
                form.render();
            });


            form.on('submit(ams_submit)', function (data) {
                data.field['data[content]'] = layedit.getContent(editindex);
                $.post('', data.field, function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { icon: 1, time: 1500 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            // parent.location.href = adminpath + '/role/index';
                            parent.location.reload();
                            parent.layer.close(index);
                            // location.href = adminpath + 'admin/combo/index';
                        });
                    } else {
                        layer.msg(res.msg, { icon: 5, time: 1500 });
                    }
                }, 'json');
                return false;
            });

        });

    </script>
</body>

</html>
